#coding=utf-8

require "aio/core"

class Aio::Module::Cmd::H3C::DisplayOspfPeer < Aio::Module::Cmd::H3C
	include Aio::Module

	def initialize
		super({
			:cmd_full			=> "display ospf peer",
			:cmd_short		=> "dis ospf p",
			:author				=> "Elin",
			:description	=> "This is H3C Command# display ospf peer",
			:ranking			=> Ranking_1,
			:platform			=> "all"
		})
	end

	def parse
		context = self.context.dup
		useful[:ospf_neighbor] = {}
		count = 0
		context.readline_range_loop(/Route/, reg_blank) do |cont|
			cont.readline_match_block(/Route/) {|b|b}
			cont.readline_match_block_loop(/(?<neighbor_id>[^\s]+) (?<address>[^\s]+) (?<pri>\d+) (.*) (?<interface>.*) (?<state>.*)/, reg_blank) do |block|
				nei = {}
				nei_id = block[:neighbor_id]
				useful[:ospf_neighbor][nei_id.to_sym] = nei
				block.update(nei, :neighbor_id)
				block.update(nei, :pri)
				block.update(nei, :state)
				block.update(nei, :address)
				block.update(nei, :interface)
				count += 1
			end
		end
	end
end
